package cn.shadow.mapper;

import cn.shadow.bean.UserInfo;
import cn.shadow.service.MyBaseMapper;
import org.apache.ibatis.annotations.*;



public interface UserMapper extends MyBaseMapper<UserInfo> {
    /**
     * 通过用户名获得用户id
     */
    @Select("select player_id from users where username = #{username} and server_id=#{serverID} and operator_id = #{operatorID} ")
    Long getUserIdByUserName(@Param("username") String username,
                             @Param("serverID") Integer serverID,
                             @Param("operatorID") Integer operatorID);

    @Insert("insert ignore into users (`username`,operator_id,server_id,create_time,update_time) values (#{userInfo.username},#{userInfo.operatorID}," +
            "#{userInfo.serverID},#{userInfo.createTime},#{userInfo.updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void createUser(@Param("userInfo") UserInfo userInfo);

    @Update("update users set player_id=#{playerId} where id=#{id} and server_id=#{serverID} and operator_id=#{operatorID}")
    void updatePlayId(@Param("playerId") Long playerId,
                      @Param("id") Integer id,
                      @Param("serverID") Integer serverID,
                      @Param("operatorID") Integer operatorID);
}
